#!/bin/bash
#
#	run_all.sh
# params: 1= start 2= gap, 3= empty/full

MAX_UP='--max_upload_rate 90'
BT_SCRATCH=/home/user/group_vod/scratch
VOD_CLIENTS=4
HOST='vm1'


case $1 in
	start)
        gap=`expr $2 \* 16`
        rm -rf $BT_SCRATCH/*

        mkdir -p $BT_SCRATCH
        chmod 0777 $BT_SCRATCH

	/home/user/group_vod/eclipse/our_scripts/run_scenario_vod.sh start $3

        sleep $gap
        thr=1
        while [ $thr -lt $VOD_CLIENTS ]
        do
                echo Spawn VOD $thr and sleep $2*16
                /usr/bin/python /home/user/group_vod/eclipse/GROUP_VOD_CODE/btdownloadheadless.py --saveas  $BT_SCRATCH/picture.$HOST-$thr.bmp --max_upload_rate 90 --security 0 --delay 5 --prefetchT 5 --rate 90 --out_dir /home/user/group_vod/csv/ --order $thr --gap $2 --group_size $VOD_CLIENTS --alg 'ORIG' /home/user/group_vod/eclipse/our_scripts/picture.$HOST.bmp.torrent& 
                sleep $gap
                thr=`expr $thr + 1`
        done
	;;
	kill)
        /home/user/group_vod/eclipse/our_scripts/run_scenario_vod.sh kill
        echo GOOD BYE 
	;;
	stop)
        sleep 10
        /home/user/group_vod/eclipse/our_scripts/run_scenario_vod.sh stop
        echo FINISHED TEST
	;;
	*)
	echo "Usage: run_all.sh [start | stop]"
	exit
	;;
esac

